package cn.net.withub.dataCollector.web.collector;

import cn.edu.hfut.dmic.webcollector.crawler.Crawler;
import cn.net.withub.dataCollector.common.model.TCollectorConfig;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
import org.springframework.web.context.ContextLoader;
import org.springframework.web.context.WebApplicationContext;

/**
 * Created by yuanjie on 2018/5/8.
 */
@Component(value="collectorM00Task")
public class CollectorM00Task {
    private Logger log = Logger.getLogger(this.getClass());

    private WebApplicationContext webContext = ContextLoader.getCurrentWebApplicationContext();


    public void crawler(TCollectorConfig config){
        try{
            if(config !=null && config.getUrl()!=null && !config.getUrl().equals("")){
                Crawler crawler = CrawlerFactory.createCrawler("crawl", true,webContext,config);
                crawler.addSeed(config.getUrl());
                crawler.setThreads(config.getThreadCount());
                crawler.setTopN(100);
                crawler.start(500);
            }
        }catch (Exception e){
            e.printStackTrace();
        }
    }

    /**
     * 抓取最高法内网 新闻聚焦 菜单导航模块下的新闻
     * @param config
     */
    public void collectorZgfxw(TCollectorConfig config){
        log.info("抓取最高院新闻......");
        try{

            if(config !=null && config.getUrl()!=null && !config.getUrl().equals("")){
                CollectorUtilsZgfnw crawler = new CollectorUtilsZgfnw("crawl", true,webContext,config);
                crawler.addSeed(config.getUrl());
                crawler.setThreads(config.getThreadCount());
                crawler.setTopN(1000);//设置爬取URL数量的上限
                //crawler.setResumable(true);
                crawler.start(500);
            }
        }catch (Exception e){
            e.printStackTrace();
        }
    }
    /**
     * 抓取法院新闻
     * @param config
     */
    public void collectorFyxw(TCollectorConfig config){
        log.info("抓取法院新闻......");
        try{
            String url = "http://149.0.160.10/news/newsListImg.shtml;jsessionid=395C9A3118D388B1490EF02CAC0F253D";
            CollectorUtils crawler = new CollectorUtils("crawl", true,webContext,config);
            crawler.addSeed(url);
            crawler.setThreads(config.getThreadCount());
            crawler.setTopN(100);
            //crawler.setResumable(true);
            crawler.start(4);
        }catch (Exception e){
            e.printStackTrace();
        }
    }

    /**
     * 抓取法院信息
     * @param config
     */
    public void collectorFyxx(TCollectorConfig config){
        log.info("抓取法院信息......");
        try{
            String url = "http://149.0.160.10/news/newsList1.shtml;jsessionid=E89FEAEE44B202700CB536E27C71CCA6?page=1&pageSize=5&categoryid=186";
            CollectorUtils crawler = new CollectorUtils("crawl", true,webContext,config);
            crawler.addSeed(url);
            crawler.setThreads(config.getThreadCount());
            crawler.setTopN(100);
            //crawler.setResumable(true);
            crawler.start(4);
        }catch (Exception e){
            e.printStackTrace();
        }
    }

    /**
     * 抓取法院简报
     * @param config
     */
    public void collectorFyjb(TCollectorConfig config){
        log.info("抓取法院简报......");
        try{
            String url = "http://149.0.160.10/news/newsList1.shtml;jsessionid=E89FEAEE44B202700CB536E27C71CCA6?page=1&pageSize=5&categoryid=5";
            CollectorUtils crawler = new CollectorUtils("crawl", true,webContext,config);
            crawler.addSeed(url);
            crawler.setThreads(config.getThreadCount());
            crawler.setTopN(100);
            //crawler.setResumable(true);
            crawler.start(4);
        }catch (Exception e){
            e.printStackTrace();
        }
    }

    /**
     * 抓取领导参阅
     * @param config
     */
    public void collectorLdcy(TCollectorConfig config){
        log.info("抓取领导参阅......");
        try{
            String url = "http://149.0.160.10/news/newsList1.shtml;jsessionid=E89FEAEE44B202700CB536E27C71CCA6?page=1&pageSize=5&categoryid=364";
            CollectorUtils crawler = new CollectorUtils("crawl", true,webContext,config);
            crawler.addSeed(url);
            crawler.setThreads(config.getThreadCount());
            crawler.setTopN(100);
            //crawler.setResumable(true);
            crawler.start(4);
        }catch (Exception e){
            e.printStackTrace();
        }
    }

    /**
     * 抓取联络督察专报
     * @param config
     */
    public void collectorLldczb(TCollectorConfig config){
        log.info("抓取联络督察专报......");
        try{
            String url = "http://149.0.160.10/news/newsList1.shtml;jsessionid=E89FEAEE44B202700CB536E27C71CCA6?page=1&pageSize=5&categoryid=721";
            CollectorUtils crawler = new CollectorUtils("crawl", true,webContext,config);
            crawler.addSeed(url);
            crawler.setThreads(config.getThreadCount());
            crawler.setTopN(100);
            //crawler.setResumable(true);
            crawler.start(4);
        }catch (Exception e){
            e.printStackTrace();
        }
    }

    /**
     * 抓取院内文件
     * @param config
     */
    public void collectorYnwj(TCollectorConfig config){
        log.info("抓取院内文件......");
        try{
            String url = "http://149.0.160.10/news/newsList1.shtml;jsessionid=E89FEAEE44B202700CB536E27C71CCA6?page=1&pageSize=5&categoryid=313";
            CollectorUtils crawler = new CollectorUtils("crawl", true,webContext,config);
            crawler.addSeed(url);
            crawler.setThreads(config.getThreadCount());
            crawler.setTopN(100);
            //crawler.setResumable(true);
            crawler.start(4);
        }catch (Exception e){
            e.printStackTrace();
        }
    }

    /**
     * 抓取上级文件
     * @param config
     */
    public void collectorSjwj(TCollectorConfig config){
        log.info("抓取上级文件......");
        try{
            String url = "http://149.0.160.10/news/newsList1.shtml;jsessionid=E89FEAEE44B202700CB536E27C71CCA6?page=1&pageSize=5&categoryid=548";
            CollectorUtils crawler = new CollectorUtils("crawl", true,webContext,config);
            crawler.addSeed(url);
            crawler.setThreads(config.getThreadCount());
            crawler.setTopN(100);
            //crawler.setResumable(true);
            crawler.start(4);
        }catch (Exception e){
            e.printStackTrace();
        }
    }

    /**
     * 抓取队伍建设
     * @param config
     */
    public void collectorDwjs(TCollectorConfig config){
        log.info("抓取队伍建设......");
        try{
            String url = "http://149.0.160.10/news/newsList1.shtml;jsessionid=E89FEAEE44B202700CB536E27C71CCA6?page=1&pageSize=5&categoryid=62";
            CollectorUtils crawler = new CollectorUtils("crawl", true,webContext,config);
            crawler.addSeed(url);
            crawler.setThreads(config.getThreadCount());
            crawler.setTopN(100);
            //crawler.setResumable(true);
            crawler.start(4);
        }catch (Exception e){
            e.printStackTrace();
        }
    }

    /**
     * 抓取一中新闻
     * @param config
     */
    public void collectorYzxw(TCollectorConfig config){
        try{
            if(config !=null && config.getUrl()!=null && !config.getUrl().equals("")){
                CollectorUtilsM10 crawler = new CollectorUtilsM10("crawl", true,webContext,config);
                crawler.addSeed(config.getUrl());
                crawler.setThreads(config.getThreadCount());
                crawler.setTopN(500);
                //crawler.setResumable(true);
                crawler.start(2);
            }
        }catch (Exception e){
            e.printStackTrace();
        }
    }
    /**
     * 抓取一中新闻
     * @param config
     */
    public void collectorFyxwByM17(TCollectorConfig config){
        try{
            if(config !=null && config.getUrl()!=null && !config.getUrl().equals("")){
                CollectorUtilsM17 crawler = new CollectorUtilsM17("crawl", true,webContext,config);
                crawler.addSeed(config.getUrl());
                crawler.setThreads(config.getThreadCount());
                crawler.setTopN(500);
                //crawler.setResumable(true);
                crawler.start(500);
            }
        }catch (Exception e){
            e.printStackTrace();
        }
    }
    /**
     * 抓取二中新闻
     * @param config
     */
    public void collectorEzxw(TCollectorConfig config){
        try{
            if(config !=null && config.getUrl()!=null && !config.getUrl().equals("")){
                CollectorUtilsM20 crawler = new CollectorUtilsM20("crawl", true,webContext,config);
                crawler.addSeed(config.getUrl());
                crawler.setThreads(config.getThreadCount());
                crawler.setTopN(1000);
                //crawler.setResumable(true);
                crawler.start(500);
            }
        }catch (Exception e){
            e.printStackTrace();
        }
    }
    /**
     * 抓取三中新闻
     * @param config
     */
    public void collectorSzxw(TCollectorConfig config){
        try{
            if(config !=null && config.getUrl()!=null && !config.getUrl().equals("")){
                CollectorUtilsM30 crawler = new CollectorUtilsM30("crawl", true,webContext,config);
                crawler.addSeed(config.getUrl());
                crawler.setThreads(config.getThreadCount());
                crawler.setTopN(1000);
                //crawler.setResumable(true);
                crawler.start(500);
            }
        }catch (Exception e){
            e.printStackTrace();
        }
    }
    /**
     * 抓取四中院新闻
     * @param config
     */
    public void collectorSzyxw(TCollectorConfig config){
        try{
            if(config !=null && config.getUrl()!=null && !config.getUrl().equals("")){
                CollectorUtilsM40 crawler = new CollectorUtilsM40("crawl", true,webContext,config);
                crawler.addSeed(config.getUrl());
                crawler.setThreads(config.getThreadCount());
                crawler.setTopN(1000);
                //crawler.setResumable(true);
                crawler.start(500);
            }
        }catch (Exception e){
            e.printStackTrace();
        }
    }
    /**
     * 抓取渝北院新闻
     * @param config
     */
    public void collectorYbxw(TCollectorConfig config){
        try{
            if(config !=null && config.getUrl()!=null && !config.getUrl().equals("")){
                CollectorUtilsM1D crawler = new CollectorUtilsM1D("crawl", true,webContext,config);
                crawler.addSeed(config.getUrl());
                crawler.setThreads(config.getThreadCount());
                crawler.setTopN(1000);
                //crawler.setResumable(true);
                crawler.start(500);
            }
        }catch (Exception e){
            e.printStackTrace();
        }
    }
    /**
     * 抓取长寿院新闻
     * @param config
     */
    public void collectorCsxw(TCollectorConfig config){
        try{
            if(config !=null && config.getUrl()!=null && !config.getUrl().equals("")){
                CollectorUtilsM1A crawler = new CollectorUtilsM1A("crawl", true,webContext,config);
                crawler.addSeed(config.getUrl());
                crawler.setThreads(config.getThreadCount());
                crawler.setTopN(1000);
                //crawler.setResumable(true);
                crawler.start(500);
            }
        }catch (Exception e){
            e.printStackTrace();
        }
    }
    /**
     * 抓取合川院新闻
     * @param config
     */
    public void collectorHcxw(TCollectorConfig config){
        try{
            if(config !=null && config.getUrl()!=null && !config.getUrl().equals("")){
                CollectorUtilsM1F crawler = new CollectorUtilsM1F("crawl", true,webContext,config);
                crawler.addSeed(config.getUrl());
                crawler.setThreads(config.getThreadCount());
                crawler.setTopN(1000);
                //crawler.setResumable(true);
                crawler.start(500);
            }
        }catch (Exception e){
            e.printStackTrace();
        }
    }

    /**
     * 抓取璧山新闻
     * @param config
     */
    public void collectorBsxw(TCollectorConfig config){
        try{
            if(config !=null && config.getUrl()!=null && !config.getUrl().equals("")){
                CollectorUtilsM1L crawler = new CollectorUtilsM1L("crawl", true,webContext,config);
                crawler.addSeed(config.getUrl());
                crawler.setThreads(config.getThreadCount());
                crawler.setTopN(1000);
                //crawler.setResumable(true);
                crawler.start(500);
            }
        }catch (Exception e){
            e.printStackTrace();
        }
    }
    /**
     * 抓取万州新闻
     * @param config
     */
    public void collectorWzxw(TCollectorConfig config){
        try{
            if(config !=null && config.getUrl()!=null && !config.getUrl().equals("")){
                CollectorUtilsM21 crawler = new CollectorUtilsM21("crawl", true,webContext,config);
                crawler.addSeed(config.getUrl());
                crawler.setThreads(config.getThreadCount());
                crawler.setTopN(1000);
                //crawler.setResumable(true);
                crawler.start(500);
            }
        }catch (Exception e){
            e.printStackTrace();
        }
    }
    /**
     * 抓取梁平新闻
     * @param config
     */
    public void collectorLpxw(TCollectorConfig config){
        try{
            if(config !=null && config.getUrl()!=null && !config.getUrl().equals("")){
                CollectorUtilsM24 crawler = new CollectorUtilsM24("crawl", true,webContext,config);
                crawler.addSeed(config.getUrl());
                crawler.setThreads(config.getThreadCount());
                crawler.setTopN(1000);
                //crawler.setResumable(true);
                crawler.start(500);
            }
        }catch (Exception e){
            e.printStackTrace();
        }
    }

    /**
     * 抓取城口新闻
     * @param config
     */
    public void collectorCkxw(TCollectorConfig config){
        try{
            if(config !=null && config.getUrl()!=null && !config.getUrl().equals("")){
                CollectorUtilsM29 crawler = new CollectorUtilsM29("crawl", true,webContext,config);
                crawler.addSeed(config.getUrl());
                crawler.setThreads(config.getThreadCount());
                crawler.setTopN(1000);
                //crawler.setResumable(true);
                crawler.start(500);
            }
        }catch (Exception e){
            e.printStackTrace();
        }
    }
    /**
     * 抓取巫溪新闻
     * @param config
     */
    public void collectorWxxw(TCollectorConfig config){
        try{
            if(config !=null && config.getUrl()!=null && !config.getUrl().equals("")){
                CollectorUtilsM28 crawler = new CollectorUtilsM28("crawl", true,webContext,config);
                crawler.addSeed(config.getUrl());
                crawler.setThreads(config.getThreadCount());
                crawler.setTopN(1000);
                //crawler.setResumable(true);
                crawler.start(500);
            }
        }catch (Exception e){
            e.printStackTrace();
        }
    }

    /**
     * 抓取武隆新闻
     * @param config
     */
    public void collectorWlxw(TCollectorConfig config){
        try{
            if(config !=null && config.getUrl()!=null && !config.getUrl().equals("")){
                CollectorUtilsM36 crawler = new CollectorUtilsM36("crawl", true,webContext,config);
                crawler.addSeed(config.getUrl());
                crawler.setThreads(config.getThreadCount());
                crawler.setTopN(1000);
                //crawler.setResumable(true);
                crawler.start(500);
            }
        }catch (Exception e){
            e.printStackTrace();
        }
    }

    /**
     * 抓取南川新闻
     * @param config
     */
    public void collectorNcxw(TCollectorConfig config){
        try{
            if(config !=null && config.getUrl()!=null && !config.getUrl().equals("")){
                CollectorUtilsM34 crawler = new CollectorUtilsM34("crawl", true,webContext,config);
                crawler.addSeed(config.getUrl());
                crawler.setThreads(config.getThreadCount());
                crawler.setTopN(1000);
                //crawler.setResumable(true);
                crawler.start(500);
            }
        }catch (Exception e){
            e.printStackTrace();
        }
    }


    /**
     * 抓取酉阳新闻
     * @param config
     */
    public void collectorYyxw(TCollectorConfig config){
        try{
            if(config !=null && config.getUrl()!=null && !config.getUrl().equals("")){
                CollectorUtilsM44 crawler = new CollectorUtilsM44("crawl", true,webContext,config);
                crawler.addSeed(config.getUrl());
                crawler.setThreads(config.getThreadCount());
                crawler.setTopN(1000);
                //crawler.setResumable(true);
                crawler.start(500);
            }
        }catch (Exception e){
            e.printStackTrace();
        }
    }

    /**
     * 抓取石柱新闻
     * @param config
     */
    public void collectorSzxxw(TCollectorConfig config){
        try{
            if(config !=null && config.getUrl()!=null && !config.getUrl().equals("")){
                CollectorUtilsM41 crawler = new CollectorUtilsM41("crawl", true,webContext,config);
                crawler.addSeed(config.getUrl());
                crawler.setThreads(config.getThreadCount());
                crawler.setTopN(500);
                //crawler.setResumable(true);
                crawler.start(500);
            }
        }catch (Exception e){
            e.printStackTrace();
        }
    }

    /**
     * 抓取渝中区新闻
     * @param config
     */
    public void collectorYzqxw(TCollectorConfig config){
        try{
            if(config !=null && config.getUrl()!=null && !config.getUrl().equals("")){
                CollectorUtilsM51 crawler = new CollectorUtilsM51("crawl", true,webContext,config);
                crawler.addSeed(config.getUrl());
                crawler.setThreads(config.getThreadCount());
                crawler.setTopN(500);
                //crawler.setResumable(true);
                crawler.start(500);
            }
        }catch (Exception e){
            e.printStackTrace();
        }
    }
    /**
     * 抓取大渡口新闻
     * @param config
     */
    public void collectorDdkxw(TCollectorConfig config){
        try{
            if(config !=null && config.getUrl()!=null && !config.getUrl().equals("")){
                CollectorUtilsM55 crawler = new CollectorUtilsM55("crawl", true,webContext,config);
                crawler.addSeed(config.getUrl());
                crawler.setThreads(config.getThreadCount());
                crawler.setTopN(500);
                //crawler.setResumable(true);
                //Config.TIMEOUT_CONNECT = 30 * 1000;
                //Config.TIMEOUT_READ = 30 * 1000;
                crawler.start(500);
            }
        }catch (Exception e){
            e.printStackTrace();
        }
    }
    /**
     * 抓取九龙坡新闻
     * @param config
     */
    public void collectorJlpxw(TCollectorConfig config){
        try{
            if(config !=null && config.getUrl()!=null && !config.getUrl().equals("")){
                CollectorUtilsM53 crawler = new CollectorUtilsM53("crawl", true,webContext,config);
                crawler.addSeed(config.getUrl());
                crawler.setThreads(config.getThreadCount());
                crawler.setTopN(500);
                //crawler.setResumable(true);
                //Config.TIMEOUT_CONNECT = 30 * 1000;
                //Config.TIMEOUT_READ = 30 * 1000;
                crawler.start(500);
            }
        }catch (Exception e){
            e.printStackTrace();
        }
    }

   

}
